package edu.buaa.act.travel.m.service;

import edu.buaa.act.travel.m.Constants;
import edu.buaa.act.travel.m.model.RunModel;
import edu.buaa.act.travel.m.page.ConfirmActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class RunReceiver extends BroadcastReceiver {
	
	private static boolean sIsConfirmRunning = false;

	@Override
	public void onReceive(Context context, Intent intent) {
		if(sIsConfirmRunning) {
			return;
		}
		
		sIsConfirmRunning = true;
		final String result = intent.getStringExtra(Constants.EXTRA_RESULT);
		final RunModel model = new RunModel(result);
		final int state = model.getState();
		if(state != 0 && state != -1) {
			final Intent i = new Intent(context, ConfirmActivity.class);
			i.putExtra(Constants.EXTRA_RUN_MODEL, model);
			i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			context.startActivity(i);
		}
	}

}
